package formbeans;

import java.util.ArrayList;

import java.util.List;

import org.mybeans.form.FormBean;

public class LoginForm extends FormBean {
	//login form input variables.
	private String userid;
	private String password;
	//private String redirect;
	//private static final String EMAIL_PATTERN = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
	//private Pattern pattern;
	//private Matcher matcher;
	
	//getter and setter.
	/*public String getRedirect(){
		return redirect;
	}*/
	public String getUserid() {
		return userid;
	}
	public String getPassword(){ 
		return password; 
    }
	//trimAndConvert trim userid, preventing html injection.
	public void setUserid(String userid) {
		this.userid = trimAndConvert(userid,"<>\"");
	}	
	/*public void setRedirect(String redirect){
		this.redirect = trimAndConvert(redirect,"<>\"");
	}*/
	public void setPassword(String password) {	
		this.password = trimAndConvert(password,"<>\"");
	}
	
	//check email adress and password format.
	public List<String> checkLoginFormErrors(){
		List<String> errors = new ArrayList<String>();
		
		if(userid == null || userid.length() == 0){
			errors.add("ID is required");
		} else if (userid.length() >= 255) {
			errors.add("ID is too long.");
		}
		if(password == null || password.length() == 0){
			errors.add("Password is required");
		} else if (password.length() >= 20) {
			errors.add("Password's length is 1-20, please re-enter.");
		}
		//if there is no error, it should be null
		return errors;
	}
	
	//using regular expression to identify email address.
	/*private boolean emailValidator(String EmailAddress){
		  pattern = Pattern.compile(EMAIL_PATTERN);
		  matcher = pattern.matcher(EmailAddress);
		  return matcher.matches();
	 }*/
}